<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<%@include file="/common/ec.jsp"%>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp" %>
<%@include file="/common/autocomplete.jsp"%>
<title>订单信息浏览</title>
<style type="text/css">
<!--
.orderSn{
  font-size: 30px;  
  color: #336699;
}

textarea{
	border:1px solid #CBCBCB;
}
-->
</style>
</head>
<body>
<script type="text/javascript">
function isNum(Oinput) {
    if (Oinput.value != null && Oinput.value != ""){
        if (Oinput.value.replace(/[\d+\.]/ig,"").length>0) {
           Oinput.value = Oinput.value.replace(/[^\d-\.]+/g,'');
        }
      }
}
function dot(arg){
    if(event.keyCode==46 && arg.value.indexOf(".")>=0){
       event.keyCode = 0;
    }
}
function save(itemId){
	var count = document.getElementById("count"+itemId).value;
	var truePrice = document.getElementById("truePrice"+itemId).value;
	if(isNaN(count)|| isNaN(truePrice)){
		 Ext.MessageBox.alert('系统提示','请正确输入数字!',function(){}); 
		return;
	}
     	$.ajax({
     		url:'${ctx}/admin/orderForm/modifyOrderItem.do',
     		type:'post',
     		dataTye:'json',
     		data:{
     				'orderItem.id' : itemId,
     				'orderItem.truePrice':truePrice,
     				'orderItem.count':count        				
     		},
     		success:function(rst,textStatus){				
     			rst = eval('('+rst+')');
     			document.getElementById("orderMoney").innerHTML = rst.orderMoney;
     			 ECSideUtil.reload('ec');
     		}, error: function(){
     	        alert('Error loading XML document');
     	    }
     	});
      
}
function remove(itemId){
	Ext.MessageBox.confirm('提示','确实要删除此订单项吗？', function(btn){
        if (btn == 'yes') {
        	$.ajax({
        		url:'${ctx}/admin/orderForm/removeCartItem.do',
        		type:'post',
        		dataTye:'json',
        		data:{
        				'orderItem.id' : itemId        				
        		},
        		success:function(rst,textStatus){				
        			rst = eval('('+rst+')');
        			document.getElementById("orderMoney").innerHTML = rst.orderMoney;
        			 ECSideUtil.reload('ec');
        		}, error: function(){
        	        alert('Error loading XML document');
        	    }
        	});
        }
    });	
}
</script>
<div class="x-panel">
<div class="x-panel-header">订单管理</div>
<div class="x-toolbar">
    <table width="100%">
      <tr>
      	<td align="left" height="22">
      		&nbsp;订单信息
      	</td>
        <td align="right" height="22">
        	<a href="${ctx}/admin/orderForm/index.do"><img src="${ctx}/images/icons/house.gif"/> 订单列表&nbsp;&nbsp;</a>
        </td>
      </tr>
    </table>
</div>
<div class="x-panel-body">

<table width="80%" align="center">
	<tr>
		<td align="center">
			<s:form id="orderForm" action="save" validate="true" theme="simple">
			<s:hidden name="model.id" />
			<fieldset style="margin: 10px;"><legend>订单基本信息</legend>
			<table  width="100%" border="0">
				<tr>
					<td style="width: 20%; text-align: right;">订单编号：</td>
					<td colspan="3" class="orderSn">${model.sn}</td>
				</tr>
				<tr>
					<td style="width: 20%; text-align: right;">下单人：</td>
					<td>${model.user.name }</td>
					<td style="width: 10%; text-align: right;">订单金额：</td>
					<td>	
						<span id="orderMoney"><fmt:formatNumber pattern="#,#00.00#" value="${model.money}"/></span>													
					</td>
				</tr>
				<tr>
					<td style="width: 20%; text-align: right;">创建时间：</td>
					<td><fmt:formatDate pattern="yyyy-MM-dd HH:mm" value="${model.createDate}"></fmt:formatDate></td>
					<td style="width: 10%; text-align: right;">到款时间：</td>
					<td>			
						<input type="text" name="model.payDate" style="width: 151px"
						value='<s:date name="model.payDate"  format="yyyy-MM-dd"/>'
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
						class="Wdate" readonly="readonly" />						
					</td>
				</tr>	
				<tr>
					<td style="width: 20%; text-align: right;">付款方信息：</td>
					<td colspan="3"><s:textarea cols="30" rows="2" name="model.payerInfo" cssStyle="width:423px; height:40px"></s:textarea></td>
				</tr>			
				<tr>
					<td style="width: 20%; text-align: right;">备&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
					<td colspan="3"><s:textarea cols="30" rows="2" name="model.descn" cssStyle="width:423px; height:40px"></s:textarea></td>
				</tr>
				<tr>
					<td style="width: 20%; text-align: right;">订单状态：</td>
					<td>
					<c:choose>
						<c:when test="${model.status eq '5'}">
							已完成
						</c:when>
						<c:otherwise>
							<s:select list="#request.adminEditStatusMap" value="model.status" name="model.status" >
							</s:select>
						</c:otherwise>
					</c:choose>
							
					<%--
						 <c:choose>					      					    
					         <c:when test="${model.status eq '2'}">
					         	审核未通过
					         </c:when>					       					       
					         <c:when test="${model.status eq '5'}">
					         	已结订单
					         </c:when>
					         <c:when test="${model.status eq '6'}">
					         	无效订单
					         </c:when>
					         <c:when test="${model.status eq '7'}">
					         	已取消
					         </c:when>
					         <c:when test="${model.status eq '8'}">
					         	已后台删除
					         </c:when>       				
					    	<c:otherwise>
					    		<c:forEach items="${statusMap}" var="statusItem" varStatus="status">												
									<input type="radio" name="model.status" ${status.index==0?'checked="checked"':''}"  value="${statusItem.key}">${statusItem.value }</input>							
								</c:forEach>
					    	</c:otherwise>
					    </c:choose>					    						   
						 --%>	
					</td>
					<td></td>
					<td></td>
				</tr>
				<tr><td height="5" colspan="2"></td></tr>
			</table>
			</fieldset>
			
					<table width="100%" style="margin-bottom: 10px;">
						<tr>
							<td colspan="2" align="center" class="font_white">
								<s:submit value="保存" cssClass="button" />&nbsp;&nbsp; 
								<s:reset value="重置" cssClass="button" /></td>
						</tr>
					</table>						
		</s:form></td>
	</tr>
</table>

</div>
<div class="x-toolbar">
 <table width="100%">
      <tr>
        <td align="left" height="22">
        	&nbsp;订单明细
        </td>
        
      </tr>
    </table>
</div>
<div class="x-panel-body">
<div style="margin-left: -3px;" align="center">
<ec:table
  items="items" var="item" retrieveRowsCallback="limit" sortRowsCallback="limit" 
  action="edit.do" 
  useAjax="true"
  doPreload="false" 
  pageSizeList="5,10,20" 
  editable="false"
  sortable="true" 
  rowsDisplayed="5" 
  generateScript="true"
  resizeColWidth="false" 
  classic="false" 
  width="100%" 
  height="210"
  minHeight="210"
  toolbarContent="navigation|pagejump|pagesize|refresh|extend|status">
  <ec:row>
    <ec:column width="40" property="_num" title="No." value="${GLOBALROWCOUNT}" sortable="false" style="text-align:center"/> 
    <ec:column width="170" property="_title" title="图书名称" style="text-align:center"> 
  	   <a href="${ctx }/book/view.do?model.id=${item.book.id}" target="_blank"><font color="blue">${item.book.name}</font></a> 
    </ec:column>
    <ec:column width="80" property="book.price" title="单价" style="text-align:center"></ec:column> 
    <ec:column width="80" property="book.truePrice" title="执行单价" style="text-align:center">
    <c:choose>
    		<c:when test="${model.status eq '0' or model.status eq '1' or model.status eq '2'}">
				<input type="text" size="6" style=" text-align: right;width: 80px;"
					id="truePrice${item.id}" 
					
					onchange="save(${item.id})"
					value="${item.truePrice}"
					/>
    		</c:when>
    		<c:otherwise>    			
    				${item.truePrice}   			
    		</c:otherwise>
    	</c:choose>		
    </ec:column>
    <ec:column width="80" property="count" style="text-align:center" title="数量">
    	<c:choose>
    		<c:when test="${model.status eq '0' or model.status eq '1' or model.status eq '2'}">
				<input type="text" size="6" style=" text-align: right;width: 80px;"
					id="count${item.id}" 
					
					onchange="save(${item.id})"
					value="${item.count}"
					/>
    		</c:when>
    		<c:otherwise>    			 			
    				${item.count}
    		</c:otherwise>
    	</c:choose>						
	</ec:column>
    <ec:column width="100" property="money"  title="金额" >
    	<div style=" margin-left:auto;margin-right:auto;text-align:center;">${item.money}</div>    	
    </ec:column>           		    
    <ec:column width="160" property="_0" title="操作" style="text-align:center" sortable="false">
    <a href="${ctx }/book/view.do?model.id=${item.id}">查看</a> |	                  
	  	<c:choose>
	  		<c:when test="${model.status eq '0' or model.status eq '1' or model.status eq '2'}">
	  		    <a href="#" onclick="remove(${item.id})">删除</a>	
	  		</c:when>
	  		<c:otherwise>
	  			<font color="#999999">删除</font>
	  		</c:otherwise>
	  	</c:choose>	          
	</ec:column>    
  </ec:row>
</ec:table>
</div>
</div>
</div>
</body>
</html>